/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mscs.server.admin.view;

import java.util.Arrays;
import java.util.List;
import java.util.Vector;
import javax.swing.table.DefaultTableModel;
import mscs.data.pojo.Person;

/**
 *
 * @author Administrator
 */
public class TableModelFactory {
    public final static Vector<String> PERSON_COLUMN_NAMES = new Vector(Arrays.asList("工号","姓名","职位"));
    
    public static DefaultTableModel getNullPersonTable(){
        return new DefaultTableModel(null, PERSON_COLUMN_NAMES);
    }
    
    public static Vector<Vector<String>> toListDataVector(List<Person> list){
        Vector<Vector<String>> newVector = new Vector<Vector<String>>();
        for(Person person: list){
            newVector.add(toStringArray(person));
        }
        return newVector;
    }
    
    private static Vector<String> toStringArray(Person person){
        Vector<String> list = new Vector<String>();
        list.add(String.valueOf(person.getId()));
        list.add(person.getName());
        switch(person.getLevel()){
            case 0: list.add("总经理");break;
            case 1: list.add("分店经理");break;
            case 2: list.add("收银员");break;
        }
        return list;
    }
    
}
